import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static java.lang.Thread.sleep;

public class demo03 {
    public static void main(String[] args) throws InterruptedException {
//        test1();
//        test2();
//        test3();
//        test4();
        test5();
    }
    //窗口切换
    private static void test1() throws InterruptedException {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#kw")).sendKeys("521");
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(3000);
        //浏览器后退
        webDriver.navigate().back();
        sleep(3000);
        //浏览器刷新
        webDriver.navigate().refresh();
        sleep(3000);
        //浏览器前进
        webDriver.navigate().forward();
        sleep(3000);

        ((JavascriptExecutor)webDriver).executeScript("document.documentElement.scrollTop=10000");
        webDriver.manage().window().maximize();
        sleep(3000);
        webDriver.manage().window().fullscreen();
        sleep(3000);
        webDriver.manage().window().setSize(new Dimension(600, 1000));
    }

    //弹窗关闭
    private static void test2() throws InterruptedException {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("https://www.baidu.com/");
        webDriver.findElement(By.cssSelector("#s-top-left > a:nth-child(1)")).click();
        sleep(3000);
//        webDriver.quit();
        webDriver.close();
    }

    //文件框处理
    private static void test3() {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("http://localhost:63342/_20230512testcode/src/main/Page/test01.html?_ijt=4brheilpuaaaoa465u843m3sth&_ij_reload=RELOAD_ON_SAVE");
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.DAYS);
        List<WebElement> webElements=webDriver.findElements(By.cssSelector("input"));
        for (int i = 0; i < webElements.size(); i++) {
            if(webElements.get(i).getAttribute("type").equals("checkbox")){
                webElements.get(i).click();
            }
        }
    }

    //上传文件
    private static void test4(){
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("http://localhost:63342/_20230512testcode/src/main/Page/test05.html?_ijt=7asvni2vctahrdl90k8v4lvq5&_ij_reload=RELOAD_ON_SAVE");
        webDriver.findElement(By.cssSelector("input")).sendKeys("D:\\111.png");
    }

    //登录框的自动化脚本
    private static void test5() throws InterruptedException {
        WebDriver webDriver=new ChromeDriver();
        webDriver.get("https://gitee.com/login");
        webDriver.findElement(By.xpath("//*[@id=\"user_login\"]")).sendKeys("123456");
        sleep(2000);
        webDriver.findElement(By.xpath("//*[@id=\"user_password\"]")).sendKeys("abcdef");
        sleep(2000);
        webDriver.findElement(By.xpath("//*[@id=\"new_user\"]/div/div/div/div[4]/input")).click();
    }

}
